﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;
using UniMana.Utils.Configs;
using UniMana.Data;

namespace UniMana.Data
{
    public class Personnel_PersonnelInfo
    {
        #region /*Không thay đổi*/
            public bds m_bds = new bds();
            public void Save()
            {
                m_data.m_DCSave.SubmitChanges();
            }
            public void Delete()
            {
                m_bds.DeleteCurrent();
            }
            #endregion /*Không thay đổi*/
            private DBMain m_data = new DBMain();
            #region [Properties - Thuộc tính]
            public Personnel_Personnel Properties
            {
                get { return m_bds.Current as Personnel_Personnel; }
            }
            #endregion
            public Personnel_PersonnelInfo(Guid personelKey)
            {
                var IQuery = m_data.m_DCSave.Personnel_Personnels.Where(p => p.Personnel_PersonnelKey == personelKey);
                m_bds.DataSource = IQuery;
                var Row = IQuery.FirstOrDefault();
                if (Row == null)
                {
                    Row = new Personnel_Personnel();
                    Row.Personnel_PersonnelKey = personelKey;
                    m_bds.Add(Row);
                }
            }
            public Personnel_PersonnelInfo()
            {
                var IQuery = m_data.m_DCSave.Personnel_Personnels.Where(p => p.Personnel_PersonnelKey == Guid.Parse( DefaultConfig.EMPTY_GUID));
                m_bds.DataSource = IQuery;
                var Row = IQuery.FirstOrDefault();
                if (Row == null)
                {
                    Row = new Personnel_Personnel();
                    m_bds.Add(Row);
                }
            }
            public Personnel_PersonnelInfo(string _strID)
            {
                var IQuery = m_data.m_DCSave.Personnel_Personnels.Where(p => p.ID == _strID);
                m_bds.DataSource = IQuery;
                var Row = IQuery.FirstOrDefault();
                if (Row == null)
                {
                    Row = new Personnel_Personnel();
                    m_bds.Add(Row);
                }
            }
            public bool CheckID(string personelID)
            {
                var str = m_data.m_DCReadOnly.Personnel_Personnels.Where(p => p.ID == personelID);
                if (str.Count() > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
    }
}
